Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1K
Vistas
i am getting this error while connecting to mongodb Atlas: "dns.exception.Timeout: The DNS operation timed out after 30.000985383987427 seconds"

i am connecting my Flask app to mongodb atlas using Flask-PyMongo, but i am getting this error.

"dns.exception.Timeout: The DNS operation timed out after 30.000985383987427 seconds"

and after that it says: During handling of the above exception, another exception occurred:

"pymongo.errors.ConfigurationError: The DNS operation timed out after 30.000985383987427 seconds"

Here's the code:

from flask import Flask 
from flask_pymongo import PyMongo

app = Flask(__name__)

app.config['MONGO_DBNAME'] = 'FirstCluster'
app.config['MONGO_URI'] = 'mongodb+srv://username:password@firstcluster-bblvc.mongodb.net/test?retryWrites=true'


mongo = PyMongo(app)

@app.route('/connect')
def connect_to_mongo():
    return 'Connecting to Mongodb'

@app.route('/collections')
def adding():
    user = mongo.db.users
    user.insert({'name' : 'vatsalay'})
    return 'Added User!'


if __name__ == '__main__':
    app.run(debug=True)
over 4 years ago · Santiago Trujillo
8 Respuestas
Responde la pregunta

0

Had the same issue, it worked for me by changing my dns from automatically to "8.8.8.8". How? If you're on Windows, do the following

  1. Open Network and internet setting
  2. Network and sharing center
  3. Press on your internet connection Wi-fi(name of your router)
  4. Go for proprieties
  5. Choose tcp/ipv4 and go to proprieties again
  6. Choose this one and edit it "use the following dns server and choose" 8.8.8.8 (google dns)

Also as Neil Lunn said check the allowed ips

over 4 years ago · Santiago Trujillo Denunciar

0

Looks like you have to install pymongo[srv] to get mongodb+srv URI to work.
Try installing it with pip3 install 'pymongo[srv]'

over 4 years ago · Santiago Trujillo Denunciar

0

Try using a different connection string. I was having problems with the 3.6 or later string. Simply used the 3.4 or later string and it connected instantly.

if you insist on using a newer connection string, you need to install pymongo srv

For Windows

pip install pymongo[srv]

For Mac

pip3 install pymongo[srv]

On zsh

pip3 install 'pymongo[srv]'
over 4 years ago · Santiago Trujillo Denunciar

0

It might be an error caused while your Mongo Client is unable to find the connection to the server. So, better check you internet connectivity and then run the program

over 4 years ago · Santiago Trujillo Denunciar

0

Same problem in Google App Engine standard.

In my case was solution to use older type of URL:

client = pymongo.MongoClient("mongodb://USERNAME:PASSWORD@CLUSTER...

SW:

  • Ubuntu 18.04
  • Python 2.7.17 / 2.7.12
  • Pymongo 3.11.1
  • Google Cloud SDK 319.0.0

Connection from test file directly from os was OK, but same code run from Google SDK dev appserver2 faile.

After change URL generated by cloud.mongodb.com Atlas in section Cluster -> Connect -> Choose a connection method -> Python - 3.4 or later connection was established.

over 4 years ago · Santiago Trujillo Denunciar

0

I was using python 3.6.2, so I chose to use the connection string for "3.6 or later". It gave me this error. Later I tried it with the connection string for "3.4 or later". It worked perfectly fine.

Try using the connection string for "3.4 or later".

over 4 years ago · Santiago Trujillo Denunciar

0

I had a similar issue. I suddenly couldn't connect. All my colleagues were using the same python version etc.

A few days before another colleague had the timeout whilst using their phones wifi. They could connect when they switched to their normal wifi.

After I rebooted my wifi I was able to connect.

It's not a great solution but it's worth trying.

over 4 years ago · Santiago Trujillo Denunciar

0

Try to use different version of connection string. You can change the version in cluster -> connect -> connect your application.

enter image description here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda